<template>
    <n-tooltip placement="bottom" trigger="hover">
        <template #trigger>
            <i class="icon iconqingli" @click.self="handleClear(0)"></i>
        </template>
        <span>清空画布</span>
    </n-tooltip>
    <n-tooltip placement="bottom" trigger="hover">
        <template #trigger>
            <i class="icon iconshanchu" @click.self="handleClear(1)"></i>
        </template>
        <span>删除</span>
    </n-tooltip>
</template>

<script setup name="ClearIcon">
import useSharedCore from '@/hooks/shared';
const { coverEditor } = useSharedCore();

function handleClear(params) {
    if (params === 0) {
        coverEditor.clear()
    } else if (params === 1) {
        // 删除选中的图层
        const activeObject = coverEditor?.canvas?.getActiveObjects();
        if (activeObject) {
            activeObject.map((item) => coverEditor.canvas.remove(item));
            coverEditor.canvas.requestRenderAll();
            coverEditor.canvas.discardActiveObject();
        }
    }
}
</script>